$(function(){
	var importData = null;
	var selectBaseDialog = null;
	init();
	Datetime();
});

//页面初始化调用方法
function init(){
	//角色拥有按钮权限
	 initButton();
	//1.初始化Table
    var oTable = new TableInit();
    oTable.Init();
    //初始化查询区类型下拉框的值
    sequenceTypeInit($("#sequenceType"),true);
    //初始化左侧基本用例树
  //树形图setting配置
	 setting = {
			  view: {
				    showLine: true,//是否显示节点之间的连线
				    fontCss:{'color':'black','font-weight':'bold'}//字体样式函数
				  },
				  data: {
				    simpleData: {//简单数据模式
				      enable:true,
				      idKey: "id",
				      pIdKey: "pId",
				      rootPId: ""
				    }
				  },
				  callback: {
				  	onClick:function(event,treeId,treeNode){
				  		var id = treeNode.id;
				  		var name = treeNode.name;
				  		if(treeNode.isParent){
				  			$('#sequenceName').val("");
						    $('#sequenceCode').val("");
						    $('#sequenceType').val(id);
						    //$('#caseTypeSearch').find("option[text='"+name+"']").attr("selected",true);
				  		}else{
				  			$('#sequenceName').val(name);
						    $('#sequenceCode').val("");
						    $('#sequenceType').val("");
				  		}
				  		$("#sequenceTables").bootstrapTable('refreshOptions',localStorage.getItem("currentSequencePage")?parseInt(localStorage.getItem("currentSequencePage")):1);
				  	}
				  }
				};
    onLoadZTree();
}

var TableInit = function () {
    var oTableInit = new Object();
    //初始化Table
    oTableInit.Init = function () {
        $('#sequenceTables').bootstrapTable({
            url: '../../../sequence/querySequenceList', //请求后台的URL（*）
            method: "POST",
            contentType : "application/x-www-form-urlencoded",
            toolbar:"#toolbar",
            striped: true,     //是否显示行间隔色
            cache: false,      //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: true,  //是否显示分页（*）
            sortable: true,  //是否启用排序
            sortName: "CREATE_TIME",
    		sortOrder: "DESC",
            checkboxHeader:false,//是否显示表头的全选
            queryParamsType : "undefined",      //排序方式
            queryParams: oTableInit.queryParams,//传递参数（*）
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber:localStorage.getItem("currentSequencePage")?parseInt(localStorage.getItem("currentSequencePage")):1,                       //初始化加载第一页，默认第一页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
            smartDisplay:false,
            search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
            strictSearch: true,
            showColumns: true,                  //是否显示所有的列
            minimumCountColumns: 2,             //最少允许的列数
            clickToSelect: true,                //是否启用点击选中行
            height: 550,                       //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            uniqueId: "id",                     //每一行的唯一标识，一般为主键列
            showToggle:true,                    //是否显示详细视图和列表视图的切换按钮
            cardView: false,                    //是否显示详细视图
            detailView: false, 
            onDblClickRow: function (item, $element) {//双击事件，item为该行数据
            	console.log(item);
            	var state = 0;
            	if(item.STATUS.indexOf('未提交')>=0){
            		state = 0;
            	}
            	if(item.STATUS.indexOf('已提交未审核')>=0){
            		state = 1;
            	}
            	if(item.STATUS.indexOf("审核并发布")>=0){
            		state = 2;
            	}
            	window.location.href="../html/sequenceEditing.html?sequenceId="+item.ID+"&state="+state+"&dataVersion="+item.DATA_VERSION;
            },
            onLoadSuccess:function(){
	            $('.bootstrap-table tr td').each(function () {
	                $(this).attr("title", $(this).text());
	                $(this).css("cursor", 'pointer');
	            });
	        },
            responseHandler: function(res) {
            	return getTableData(res);
            },      //是否显示父子表
            columns: [{
                checkbox: true,
                title:"选择",
                width:30
            }, {
                field: 'CODE',
                title: '测试序列编号',
                width:150,
				cellStyle:{ 
					css:{ 
					"overflow": "hidden", 
					"text-overflow": "ellipsis", 
					"white-space": "nowrap" 
					} 
					}
            }, {
                field: 'NAME',
                title: '测试序列名称',
                width:150,
				cellStyle:{ 
					css:{ 
					"overflow": "hidden", 
					"text-overflow": "ellipsis", 
					"white-space": "nowrap" 
					} 
					}
            }, {
                field: 'TNAME',
                title: '测试序列类型',
                width:150
            },{
                field: 'STATUS',
                title: '测试序列状态',
                width:100
            }, {
                field: 'DESCRIBE',
                title: '测试序列描述',
                width: 350,
				cellStyle:{ 
					css:{ 
					"overflow": "hidden", 
					"text-overflow": "ellipsis", 
					"white-space": "nowrap" 
					} 
					}
            }, {
                field: 'VERSION',
                title: '序列版本',
                width:80
            }, {
                field: 'IS_DEL',
                title: '版本状态',
                width:80,
                formatter: versionStatus
            }, {
                field: 'CREATE_USER',
                title: '创建人',
                width:100
            }, {
                field: 'DEP_NAME',
                title: '创建人部门',
                width:100
            }, {
            	field: 'CREATE_TIME',
                title: '创建日期',
                width:150
            },{
                field: 'SEQUENCE_AUDITOR',
                title: '审核人',
                width:100
            }, {
            	field: 'AUDIT_TIME',
                title: '审核日期',
                width:150
            }, {
				field: 'SEQUENCE_OPINION',
				title: '审核意见',
				width: 250,
				cellStyle:{ 
					css:{ 
					"overflow": "hidden", 
					"text-overflow": "ellipsis", 
					"white-space": "nowrap" 
					} 
					}
			}]
        });
    };

    //得到查询的参数
    oTableInit.queryParams = function (params) {
    	localStorage.setItem("currentSequencePage", params.pageNumber);
        var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的pageSize, pageNumber, searchText, sortName, sortOrder
        		pageSize: params.pageSize,   //页面大小
        		pageNumber: params.pageNumber,  //页码
        		sortName: params.sortName,
        		sortOrder: params.sortOrder,
        		sequenceName: $('#sequenceName').val(),
        		sequenceCode: $('#sequenceCode').val(),
        		sequenceType : $('#sequenceType').val(),
        		type: $('#caseTypeSearch').val(),
    			createUser:$('#createrSearch').val(),
    			startTime : $("#astsSysLogLoginTime input").val(),
    			endTime : $("#astsSysLogEndTime input").val(),
        };
        return temp;
    };
    return oTableInit;
};

function versionStatus(value, row, index) {
	if (row['IS_DEL'] == "0") {
		return "启用";
	} else {
		return "禁用";
	}
}

function sequenceTypeInit(comboContainer,type){
	//comboContainer为combobox所在的容器
	//type:是否支持输入自动过滤选项功能
	/* 用例类别数据获取 */
	$.ajax({
		url : '../../../sequence/getSequenceTypeList',
		type : "GET",
		success : function(obj) {
			if(obj.flag==0){
				var resultc = obj.content;
				comboContainer.append("<option value='' selected='selected'>请选择</option>");
				for (var i = 0; i < resultc.length; i++) {
					/* 创建option并插入数据 */
					comboContainer.append(
							"<option value='" + resultc[i].CODE + "'>"
									+ resultc[i].NAME + "</option>");
				}
				if(type){
					comboContainer.combobox();
				}
			}else{
				danger(obj.errorInfo);
			}
			
		},
		error : function(error) {
			danger("获取序列类型异常");
		}

	});
	
	var wenArray = [{id:"1",type:'9',text:'车载数据文件',divId:'chezaiselect'},{id:"1",type:'10',text:'运行组织文件',divId:'yunxingselect'}];
	for(var i = 0;i<wenArray.length;i++){
		$("#"+wenArray[i].divId).append(getWenJianData(wenArray[i].id,wenArray[i].type));
	}
}

//
function getWenJianData(id,type){
	var str="";
	$.ajax({
		url : "../../../LKJSoftwareVersion/getVersionName",
		type : "post",
		data : {
			"sId" : id,
			"type" : type
		},
		dataType : "json",
		async:false,
		success : function(data) {
			if(data.flag==0){
				var content = data.content;
				str=ajaxOption(content);
			}
		},
		error : function() {
		}
	});
	return str;
}
//将查询到的下拉内容组合放到对应的位置
function ajaxOption(content){
	var str="<option value=''></option>";
	if(content!=""&&content!=null){
		for(var i=0;i<content.length;i++){
			str+="<option value="+content[i].VERSION_ID+">"+content[i].VERSION_NAME+"</option>";
		};
	}
	return str;
}

//加载zTree树形图
function onLoadZTree(){
				  var treeNodes;
				  var treeSelect = $('#rush').val();
				  $.ajax({
				    async:false,//是否异步
				    cache:false,//是否使用缓存
				    data:{sequenceName:treeSelect},
				    type:'POST',//请求方式：post
				    dataType:'json',//数据传输格式：json
				    url:"../../../sequence/querySequenceTree",//请求路径
				    error:function(){
				      //请求失败处理函数
				      danger('请求失败！');
				    },
				    success:function(data){
						if(data.flag==0){
							//请求成功后处理函数
							treeNodes = data.content;//把后台封装好的简单Json格式赋给treeNodes
							var zTree = $("#tree");
							zTree = $.fn.zTree.init(zTree, setting, treeNodes);
						}else{
							danger(data.errorInfo);
						}
					}
				  });
				}


function addSequence() {
    BootstrapDialog.show({
    	title: '新增测试序列基本信息',
    	draggable: true,
		closable: false,
        message: $("<form class='form-inline' style='height:360px'></form>").load('sequenceAdd.html')  ,
        onshown:function(){
        	//初始化新增页面类型的值
        	sequenceTypeInit($("#sequenceTypeInAdd"),false);
        },
        buttons: [{
            icon: 'glyphicon glyphicon-check',
            label: '下一步',
            cssClass: 'btn-primary',
            autospin: true,
            action: function(dialogRef){
            	var sequenceType = $("#sequenceTypeInAdd").val().trim();
            	var sequenceName = $("#sequenceNameInAdd").val().trim();
            	var sequenceNum = $("#sequenceNumInAdd").val().trim();
            	var sequenceDescribe = $("#sequenceDescribeInAdd").val().trim();
            	// 判断类型是否为空
                if(sequenceType==""){
				   warning("请选择测试序列类型！");
                   return false;
                }
            	 // 判断名称是否为空
                if(sequenceName==""){
                	warning("测试序列名称不能为空！");
                       return false;
                }
             // 判断名称过长
                if(sequenceName.length>=25){
                	warning("测试序列名称不能超过25个字符！");
                       return false;
                }
                // 判断编号是否为空
                if(sequenceNum==""){
					warning("测试序列编号不能为空！");
                       return false;
                }
                // 判断编号过长
                if(sequenceNum.length>=25){
					warning("测试序列编号不能超过25个字符！");
                       return false;
                }
                // 判断描述是否为空
                if(sequenceDescribe==""){
					warning("测试序列描述描述不能为空！");
                     return false;
                }
                // 判断描述过长
                if(sequenceDescribe.length>=1000){
					warning("测试序列描述不能超过1000个字符！");
                       return false;
                }
                if($('#chezaiselect').val()==""){
					warning("车载数据文件不能为空！");
                     return false;
                }
                if($('#yunxingselect').val()==""){
					warning("运行组织文件不能为空！");
                     return false;
                }
    		/* ajax向后台发送新建用例的数据 */
    		$.ajax({
    			type : "POST",
    			url : "../../../sequence/addSequence",
    			data : {
    				"sequenceType" : sequenceType,
    				"sequenceName" : sequenceName,
    				"sequenceCode":sequenceNum,
    				"sequenceDescribe" : sequenceDescribe,
    				"dataVersion":$('#chezaiselect').val(),
    				"yxjlVersion":$('#yunxingselect').val()
    			},
    			success : function(data) {
    				var flag = data.flag;
    				if (flag == 0) {
    					addBaseCaseId = data.content.sequenceId;
    					BootstrapDialog.alert({ title: '提示',
    			            message: "测试序列新增成功!",
    			            type: BootstrapDialog.TYPE_SUCCESS});
    					setTimeout(function (){
    						BootstrapDialog.closeAll();
    						// 点击确定按钮后跳转到测试序列管理界面并将ID传给下一个页面
    			    		window.location.href="../html/sequenceEditing.html?sequenceId="+addBaseCaseId+"&state="+0+"&dataVersion="+$('#chezaiselect').val();
    					},800);
    				}  else  {
    					danger(data.errorInfo);
    				}
    			},
    			error : function(err) {
    				danger("服务器异常!");
    			}
    		});
            }
        }, {
            label: '取消',
            action: function(dialogRef){
                dialogRef.close();
            }            
        }]
    });
}

function deleteSequence(){
	var selectSequence= $("#sequenceTables").bootstrapTable('getSelections'); 
	if (selectSequence.length == 0) {
		warning("请选择要删除的测试序列信息!");
	} else {
		if (selectSequence.length == 1) {
			var sequenceId = selectSequence[0].ID;
			deleteBootStrapShow(sequenceId);
		}else{
			deleteMoreBootStrapShow(selectSequence);
		}
	}
}

//删除多条基本用例提示框，传入参数为基本用例id 集合
function deleteMoreBootStrapShow(selectSequence){
	BootstrapDialog.show({
		title : '提示',
		message :"您确定要删除吗?",
		buttons : [{
			icon : 'glyphicon glyphicon-check',
			label : '确定',
			cssClass : 'btn-primary',
			autospin : true,
			action:function(dialogRef){
				dialogRef.close();
				for (var i = 0; i < selectSequence.length; i++) {
					var sequenceId = selectSequence[i].ID;
					deleteSequenceAjax(sequenceId);
				}
			}
		},{
			label : '取消',
			action : function(dialogRef) {
				dialogRef.close();
			}
		}]
	});
}
//删除单条基本用例提示框，传入参数为基本用例id
function deleteBootStrapShow(sequenceId){
	BootstrapDialog.show({
		title : '提示',
		message :"您确定要删除吗?",
		buttons : [{
			icon : 'glyphicon glyphicon-check',
			label : '确定',
			cssClass : 'btn-primary',
			autospin : true,
			action:function(dialogRef){
				dialogRef.close();
				deleteSequenceAjax(sequenceId);
			}
		},{
			label : '取消',
			action : function(dialogRef) {
				dialogRef.close();
			}
		}]
	});
}

function deleteSequenceAjax(sequenceId){
	$.ajax({
		 url:"../../../sequence/deleteSequence",
	        type:"POST",
	        data:{"sequenceId":sequenceId},
	        success:function(data){
	            var flag = data.flag;
	            if(flag==0){
	            	var content = "测试序列删除成功!";
	            	success(content);
	            	$("#sequenceTables").bootstrapTable('refreshOptions',localStorage.getItem("currentSequencePage")?parseInt(localStorage.getItem("currentSequencePage")):1);
	            }else if(flag == 1){
	            	var content = "此序列在使用中，无法删除序列！";
	            	warning(content);
	            }else if(flag == 2){
	            	var content = "其他用户序列无权操作！";
	            	warning(content);
	            }else if(flag == 3){
	            	var content = "已发布序列无法删除！";
	            	warning(content);
	            }
	        },
	        error:function(data){
	        	var content = "测试序列删除失败!";
	        	danger(content);
	        }
	});
}

function exportFile(index){
	var idString = "";
	   //导出所选
		var selectClass = $('#sequenceTables').bootstrapTable('getSelections');
		if(selectClass.length<=0){
			danger('请选择要导出的测试序列！');
			return;
		}
		for(var i = 0;i<selectClass.length;i++){
			if(i<selectClass.length-1){
				idString = idString+selectClass[i].ID+',';
			}else{
				idString = idString+selectClass[i].ID;
			}
		}
	window.location.href="../../../sequence/exportTestSequenceJson?sequenceId="+idString;
}

function importFile() {
	document.getElementById("file-upload").click();
}
/**
 * 判断是否选择的有文件
 */
function selectFile() {

	var formData = new FormData($("#uploadForm")[0]);

//	$('.sequence-import-pop-content').html(
//		'<div class="checkbox" id="select-all">' +
//		'<label>' +
//		'<input type="checkbox">' +
//		'全选'+
//		'</label>' +
//		'</div>'
//	);
//	$('#select-all input').unbind("change");
//	$('#select-all input').change(function() {
//		if (this.checked) {
//			$(".sequence-import-pop-content input").each(function() {
//				$(this).prop("checked", true);
//			});
//		} else {
//			$(".sequence-import-pop-content input").each(function() {
//				$(this).prop("checked", false);
//				// $("." + id).find("input[type='checkbox']").removeAttr("checked"); 
//			});
//		}
//	});
	$.ajax({
		url: "../../../sequence/decryptTestSequenceFile",
		type: 'POST',
		data: formData,
		async: false,
		cache: false,
		contentType: false,
		processData: false,
		success: function(returndata) {
			console.log(returndata);
			//获取解密后的文件
			if (returndata.flag == 0) {
				importData = returndata.content;
//				$(".sequence-import-pop").fadeIn(300);
//				for (var index = 0; index < importData.length; index++) {
//					var indexValue = importData[index];
//					$('.sequence-import-pop-content').append(
//						'<div class="checkbox">' +
//						'<label>' +
//						'<input type="checkbox">' +
//						index + '、' + indexValue.id + "--" + indexValue.sequenceExport.sequenceName + '' +
//						'</label>' +
//						'</div>'
//					);
//				}
				if(importData.length>0){
					selectImportFileDi();
				}else{
					danger("无可导入测试序列或者导入的测试序列已经存在！");
				}
			}else{
				danger(returndata.errorInfo);
			}
		},
		error: function(returndata) {
			console.log(returndata);
		}
	});
	$('#file-upload').val("");
}
//真正导入，首先获取用户选择的东西。
function importFileStepTwo() {
	var arrayIndex = [];
	$('input:checkbox[name=checkItem]:checked').each(function(i){
		arrayIndex.push(Number($(this).parent().parent()[0].id.split('_')[1]));
	});
	if(arrayIndex.length<=0){
		danger("请选择要导入的测试序列！");
		return;
	}
	
	var importDataArray = [];
	for (var index = 0; index < importData.length; index++) {
		for(var j = 0;j<arrayIndex.length;j++){
			if(arrayIndex[j] == index){
				importDataArray.push(importData[index]);
			}
		}
	}
	$.ajax({
		async: false, //是否异步
		cache: false, //是否使用缓存
		data: {
			testSequenceString: JSON.stringify(importDataArray)
		},
		type: 'POST', //请求方式：post
		dataType: 'json', //数据传输格式：json
		url: "../../../sequence/uploadTestSequenceFile", //请求路径
		error: function(e) {
			//请求失败处理函数
			danger("导入失败！");
			console.log(e);
		},
		success: function(data) {
			//请求成功后处理函数
			selectBaseDialog.close();
			$("#sequenceTables").bootstrapTable('refreshOptions',localStorage.getItem("currentSequencePage")?parseInt(localStorage.getItem("currentSequencePage")):1);
			var t = BootstrapDialog.alert({
				title: '提示',
				message: "导入成功!",
				type: BootstrapDialog.TYPE_SUCCESS
			});
			setTimeout(function() {
				t.close();
			}, 800);
		}
	});
}

function initButton(){
	var add = document.getElementById("btn_add");
	var deleteBtn = document.getElementById("btn_delete");
	var noRealDeleteBtn = document.getElementById("btn_noRealDelete");
	if(roleButton().indexOf("csxlbj")!=-1){
		add.style.display="block";
	}
	if(roleButton().indexOf("csxlsc")!=-1){
		deleteBtn.style.display="block";
		noRealDeleteBtn.style.display = "block";
	}
}

//选择要导入的测试序列
function selectImportFileDi() {
	selectBaseDialog = BootstrapDialog.show({
		title: '导入测试序列信息',
		message: $("<form class='form-inline' style='height:300px'></form>").load('selectSequenceListView.html'),
		onshown: function() {
			initTableCheckbox();
		},
		buttons: [{
			icon: 'glyphicon glyphicon-check',
			label: '确定',
			cssClass: 'btn-primary',
			autospin: true,
			action: function(dialogRef) {
				importFileStepTwo();
			}
		}, {
			label: '取消',
			action: function(dialogRef) {
				dialogRef.close();
			}
		}]
	});
}

//更新可以导入的基本用例
function initTableCheckbox() {
	var htmlData= "";
	for(var i = 0;i<importData.length;i++){
		htmlData = htmlData+"<tr id=selectTr_"+i+"><td>"+importData[i].sequenceId+"</td>"+"<td>"+importData[i].sequenceCode+"</td>"+
		"<td>"+importData[i].sequenceName+"</td></tr>";
	}
	$('#tableTbody').html(htmlData);
	var $thr = $('#selectTr');
	var $checkAllTh = $('<th><input type="checkbox" id="checkAll" name="checkAll" /></th>');
	/*将全选/反选复选框添加到表头最前，即增加一列*/
	$thr.prepend($checkAllTh);
	/*“全选/反选”复选框*/
	var $checkAll = $thr.find('input');
	$checkAll.click(function(event) {
		/*将所有行的选中状态设成全选框的选中状态*/
		$tbr.find('input').prop('checked', $(this).prop('checked'));
		/*并调整所有选中行的CSS样式*/
		if($(this).prop('checked')) {
			$tbr.find('input').parent().parent().addClass('warning');
		} else {
			$tbr.find('input').parent().parent().removeClass('warning');
		}
		/*阻止向上冒泡，以防再次触发点击操作*/
		event.stopPropagation();
	});
	/*点击全选框所在单元格时也触发全选框的点击操作*/
	$checkAllTh.click(function() {
		$('#selectBaseTable').find('input').click();
	});
	var $tbr = $('#tableTbody').find('tr');
	var $checkItemTd = $('<td><input type="checkbox" name="checkItem" /></td>');
	/*每一行都在最前面插入一个选中复选框的单元格*/
	$tbr.prepend($checkItemTd);
	/*点击每一行的选中复选框时*/
	$tbr.find('input').click(function(event) {
		/*调整选中行的CSS样式*/
		$(this).parent().parent().toggleClass('warning');
		/*如果已经被选中行的行数等于表格的数据行数，将全选框设为选中状态，否则设为未选中状态*/
		$checkAll.prop('checked', $tbr.find('input:checked').length == $tbr.length ? true : false);
		/*阻止向上冒泡，以防再次触发点击操作*/
		event.stopPropagation();
	});
	/*点击每一行时也触发该行的选中操作*/
	$tbr.click(function() {
		$(this).find('input').click();
	});
}



//弹出编辑脚本的弹窗
function editScript(){
	var selectClass = $('#sequenceTables').bootstrapTable('getSelections');
	if(selectClass.length<=0){
		warning('请选择要编辑的测试序列！');
		return;
	}
	
	BootstrapDialog.show({
		title: '编辑脚本',
		message: $("<form class='form-inline' style='height:550px;'></form>").load('baseCaseScriptEdit.html'),
		onshown: function() {
			$('.modal-dialog').css('width','48%');
			showScript();
		},
		buttons: [{
			icon: 'glyphicon glyphicon-check',
			label: '确定',
			cssClass: 'btn-primary',
			autospin: true,
			action: function(dialogRef) {
				sendScript(dialogRef);
			}
		}, {
			label: '取消',
			action: function(dialogRef) {
				dialogRef.close();
			}
		}]
	});
}

//界面中显示现在的脚本
function showScript(){
	var selectClass = $('#sequenceTables').bootstrapTable('getSelections');
	$.ajax({
		type:'POST',
		url:'../../../sequence/querySequenceScriptBySequenceId',
		data:{
			'sequenceId':selectClass[0].ID
		},
		success:function(data){
			console.log(data);
			if(data.flag == 0){
				$('#scriptText').html(editScriptString(data.content));
			}else{
				danger(data.errorInfo);
			}
		},
		error:function(error){
			danger(error.errorInfo);
		}
	});
}
//发送脚本编辑请求
function sendScript(dialogRef){
	var selectClass = $('#sequenceTables').bootstrapTable('getSelections');
	var caseContent = $("#scriptText").val();
	if(caseContent == ""){
		warning("请输入脚本！");
		return;
	}
	$.ajax({
		type:'POST',
		url:'../../../sequence/updateSequenceScriptBySequenceId',
		data:{
			'sequenceId':selectClass[0].ID,
			'content':caseContent
		},
		success:function(data){
			console.log(data);
			if(data.flag == 0){
				var t = BootstrapDialog.alert({ 
					title: '提示',
		            message: '编辑成功！',
		            type: BootstrapDialog.TYPE_SUCCESS
		        });
				setTimeout(function (){
					t.close();
					dialogRef.close();
				},800);
			}else{
		        warning(data.errorInfo);
			}
			
		},
		error:function(error){
			warning(data.errorInfo);
		}
	});
}

//脚本字符串处理
function editScriptString(str){
	var reg = /;/g;
	return str.replace(reg,';\n');
}
function onKeyUpFun(event,count){
	if(event.value.length>count){
		warning('输入不能超过'+count+"个字符");
	}
}
//检验时间空间输入的
function set_Time_value(th) {// th this用来获取属性值，ys就是整个元素对象
	if (!checkDateTime($(th).val())) {// 输入的时间格式校验
		$(th).val('');
		return;
	}
}
//时间格式校验
function checkDateTime(date) {
	var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
	var r = date.match(reg);
	if (r != null || date == '') {
		return true;
	} else {
		warning("输入格式不正确，请按yyyy-MM-dd HH:mm:ss的格式输入！");
		return false;
	}
}

//设置日期时间控件
function Datetime() {
	$('#datetimepicker2').datetimepicker({
		language : 'zh-CN',// 显示中文
		format : 'yyyy-mm-dd hh:ii:ss',// 显示格式
		minView : 0,// 设置只显示到月份
		initialDate : new Date(),
		autoclose : true,// 选中自动关闭
		todayBtn : true,// 显示今日按钮
		locale : moment.locale('zh-cn'),
	}).on('changeDate', function(ev) {
		$('#timeSearch').val(formatDateTime(Number(ev.date.valueOf())));
	});
	$('#datetimepickerEnd2').datetimepicker({
		language : 'zh-CN',// 显示中文
		format : 'yyyy-mm-dd hh:ii:ss',// 显示格式
		minView : 0,// 设置只显示到月份
		initialDate : new Date(),
		autoclose : true,// 选中自动关闭
		todayBtn : true,// 显示今日按钮
		locale : moment.locale('zh-cn'),
	}).on('changeDate', function(ev) {
		$('#timeSearch2').val(formatDateTime(Number(ev.date.valueOf())));
	});
}

function formatDateTime(inputTime) {
	var date = new Date(inputTime);
	var y = date.getFullYear();
	var m = date.getMonth() + 1;
	m = m < 10 ? ('0' + m) : m;
	var d = date.getDate();
	d = d < 10 ? ('0' + d) : d;
	var h = date.getHours();
	h = h < 10 ? ('0' + h) : h;
	var minute = date.getMinutes();
	var second = date.getSeconds();
	minute = minute < 10 ? ('0' + minute) : minute;
	second = second < 10 ? ('0' + second) : second;
	return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
}

//假删除
function noRealDeleteBaseCase(){
	var selectVersion = $("#sequenceTables").bootstrapTable('getSelections');
	console.log(selectVersion);
	if (selectVersion.length == 0) {
		var content = "请选择要删除的测试序列!";
		info(content);
	} else {
		BootstrapDialog.show({
			title: '提示',
			message: "您确定要删除吗?",
			buttons: [{
				icon: 'glyphicon glyphicon-check',
				label: '确定',
				cssClass: 'btn-primary',
				autospin: true,
				action: function(dialogRef) {
					dialogRef.close();
					noDelectFun(selectVersion[0].ID,1);
				}
			}, {
				label: '取消',
				action: function(dialogRef) {
					dialogRef.close();
				}
			}]
		});
	}
}

function noDelectFun(id,statu){
	$.ajax({
		"url" : "../../../sequence/updateDelStatusBysequenceId",
		"type" : "post",
		"data" : { 
			seqeuenceId:id,
			isDel:statu
		},
		"dataType" : "json",
		"success" : function(result) {
			console.log(result);
			if(result.flag==0){
				success(result.content);
				$("#sequenceTables").bootstrapTable('refreshOptions',localStorage.getItem("currentSequencePage")?parseInt(localStorage.getItem("currentSequencePage")):1);
			}else{
				warning(result.errorInfo);
			}
		},
		"error" : function(data) {
			warning(data.errorInfo);
		}
	});
}
//相识度
function semblanceFun(){
	var selectClass = $('#sequenceTables').bootstrapTable('getSelections');
	if(selectClass.length !=2){
		warning('请选择两个测试序列！');
		return;
	}
	
	$.ajax({
		"url" : "../../../sequence/getSimilarityBySequenceId",
		"type" : "post",
		"data" : { 
			sequenceId1:selectClass[0].ID,
			sequenceId2:selectClass[1].ID
		},
		"dataType" : "json",
		"success" : function(result) {
			console.log(result);
			if(result.flag==0){
				success("相似度："+result.content);
			}else{
				warning(result.errorInfo);
			}
		},
		"error" : function(data) {
			warning(data.errorInfo);
		}
	});
}